package flux;

import java.io.File;
import java.io.FileFilter;
import phoenix.FanartAPI;;



public class fanart {
	
	// All calls below are temporary until they are added to phoenix api. 
	// The return of Season calls returns series if no season is available. Always use phoenix
	// HasFanart calls before hand in studio to avoid nulls.
  
public static String GetSeasonFanartPoster(Object MediaObject)
  {
	  String NewFanart = "none";
	  File directory = new File(phoenix.api.GetFanartPosterPath(MediaObject));
      File[] AllFanart = directory.listFiles(new Filter());
       if(AllFanart != null)
        {
        NewFanart = AllFanart[0].toString();
        }
       else{
    	NewFanart = fanart.GetSeriesFanartPoster(MediaObject);
       }
	   return NewFanart;
        
        }
    
 
 public static String GetSeriesFanartPoster(Object MediaObject)
 {
	 String NewFanart = null;
	 String Title = airing.GetAiringTitle(MediaObject);
	 String SeriesPath = phoenix.api.GetFanartCentralFolder() + "\\TV\\" + Title +
		 "\\Posters";
	 
	 File directory = new File(SeriesPath);
	 File[] AllFanart = directory.listFiles(new Filter());
	 if(AllFanart != null)
     {
     NewFanart = AllFanart[0].toString();
     }
		return NewFanart;
         }
 
 public static String GetSeasonFanartBanner(Object MediaObject)
 {
	  String NewFanart = "none";
	  File directory = new File(phoenix.api.GetFanartBannerPath(MediaObject));
     File[] AllFanart = directory.listFiles(new Filter());
      if(AllFanart != null){
       NewFanart = AllFanart[0].toString();}
      else{
   	NewFanart = fanart.GetSeriesFanartPoster(MediaObject);}
	   return NewFanart;
       
       }
   

public static String GetSeriesFanartBanner(Object MediaObject)
{
	 String NewFanart = null;
	 String Title = airing.GetAiringTitle(MediaObject);
	 String SeriesPath = phoenix.api.GetFanartCentralFolder() + "\\TV\\" + Title +
		 "\\Banners";
	 
	 File directory = new File(SeriesPath);
	 File[] AllFanart = directory.listFiles(new Filter());
	 if(AllFanart != null){
     NewFanart = AllFanart[0].toString();}
		return NewFanart;}

public static File[] GetSeasonFanartPosters(Object MediaObject)
{
	  
	  File directory = new File(phoenix.api.GetFanartPosterPath(MediaObject));
      File[] AllFanart = directory.listFiles(new Filter());
     if(AllFanart != null)
      {
      return AllFanart;
      }
     else{
  	AllFanart = fanart.GetSeriesFanartPosters(MediaObject);
     }
	   return AllFanart;
      
      } 
public static File[] GetSeriesFanartPosters(Object MediaObject)
{
	 String Title = airing.GetAiringTitle(MediaObject);
	 String SeriesPath = phoenix.api.GetFanartCentralFolder() + "\\TV\\" + Title +
		 "\\Posters";
	 
	 File directory = new File(SeriesPath);
	 File[] AllFanart = directory.listFiles(new Filter());
	 if(AllFanart != null)
    {
    return AllFanart;
    }
		return AllFanart = null;
        }

}


class Filter implements FileFilter  
{  
   public boolean accept(File file)  
   {  
      return file.getName().contains("jpg");  
   }  
}

